package com.heiye.quiz.biz.rpc;

import cn.hutool.core.collection.CollUtil;
import com.heiye.count.api.api.CountFeignApi;
import com.heiye.count.api.dto.FindQuizCountsByIdRspDTO;
import com.heiye.count.api.dto.FindQuizCountsByIdsReqDTO;
import com.heiye.framework.common.response.Response;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * @author: heiye
 * @date: 2025/07/14 下午12:14
 * @version: v1.0.0
 * @description: 计数服务
 */
@Component
public class CountRpcService {

    @Resource
    private CountFeignApi countFeignApi;

    /**
     * 根据问题 IDS 批量查询问题计数
     *
     * @param quizIds
     * @return
     */
    public List<FindQuizCountsByIdRspDTO> findByQuizIds(List<Long> quizIds) {
        FindQuizCountsByIdsReqDTO findQuizCountsByIdsReqDTO = new FindQuizCountsByIdsReqDTO();
        findQuizCountsByIdsReqDTO.setQuizIds(quizIds);

        Response<List<FindQuizCountsByIdRspDTO>> response = countFeignApi.findQuizzesData(findQuizCountsByIdsReqDTO);

        if (!response.isSuccess() || Objects.isNull(response.getData()) || CollUtil.isEmpty(response.getData())) {
            return null;
        }
        return response.getData();
    }
}
